package com.suxin.plugin.intergration.manager.repository;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BooleanSupplier;

/**
 * @author Tang
 * @classname CompoundPluginRepository
 * @description [  ]
 * @date 2022/7/3 21:15
 */
public class CompoundPluginRepository implements PluginRepository {

    List<PluginRepository> pluginRepositories = new ArrayList<>(16);

    @Override
    public List<Path> getPluginPaths() {
        Set<Path> paths = new LinkedHashSet<>();
        for (PluginRepository pluginRepository : pluginRepositories) {
            paths.addAll(pluginRepository.getPluginPaths());
        }
        return new ArrayList<>(paths);
    }

    @Override
    public boolean deletePluginPath(Path pluginPath) {
        return false;
    }

    public CompoundPluginRepository add(PluginRepository repository) {
        pluginRepositories.add(repository);
        return this;
    }

    public CompoundPluginRepository add(PluginRepository repository, BooleanSupplier supplier) {
        if (supplier.getAsBoolean()) {
            pluginRepositories.add(repository);
        }
        return this;
    }
}